package com.example.dockercompose.dao;

import org.apache.ibatis.io.Resources;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;

public class Schemas {
    public static List<String> allSQLs() throws IOException {
        File schemasDir = Resources.getResourceAsFile("data");

        List<String> result = new ArrayList<>();
        allSQLs(schemasDir, result);
        return result;
    }

    public static void allSQLs(File file, List<String> list) throws IOException {
        if (file.isDirectory()) {
            for (File f : file.listFiles()) {
                allSQLs(f, list);
            }
        } else {
            list.add(new String(Files.readAllBytes(file.toPath())));
        }
    }
}
